Only check for valid timestamps if really needed.
authoroliskoli <oliskoli>
Mon, 8 Jan 2007 22:04:32 +0000 (22:04 +0000)
committeroliskoli <oliskoli>
Mon, 8 Jan 2007 22:04:32 +0000 (22:04 +0000)
Based on patch from Vladimir Kondratiev.

trackfilter.c

index 1dde8ddf3c35ffec34af14cc3f75fc717db3bcbf..6b209b8cde5288ff63e58ed4defec3bce9656a47 100644 (file)
@@ -2,7 +2,7 @@
 
     Track manipulation filter
 
-    Copyright (C) 2005 Olaf Klein, o.b.klein@gpsbabel.org
+    Copyright (C) 2005-2006 Olaf Klein, o.b.klein@gpsbabel.org
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     2005-07-26: implemented move option
     2005-07-26: implemented merge option
     2005-07-29: warning fixes
-    2005-08-01: Add 'static' qualifier when we can (RJL)
-    2005-10-04: Add filterdefs to hold protos for filter functions... (RJL)
+    2005-08-01: Add 'static' qualifier when we can (robertl)
+    2005-10-04: Add filterdefs to hold protos for filter functions... (robertl)
     2005-10-04: Fix range-check max. value; exit filter, if no more tracks left
-    2006-04-06: Add fix, course, and speed options
+    2006-04-06: Add fix, course, and speed options (parkrrrr)
     2006-06-01: Add name option
+    2007-01-08: if not really needed disable check for valid timestamps
+               (based on patch from Vladimir Kondratiev)
  */
  
 #include <ctype.h>
@@ -119,6 +121,7 @@ static int track_ct = 0;
 static int track_pts = 0;
 static int opt_interval = 0;
 static int opt_distance = 0;
+static char need_time;         /* initialized within trackfilter_init */
 
 /*******************************************************************************
 * helpers
@@ -251,8 +254,8 @@ trackfilter_fill_track_list_cb(const route_head *track)     /* callback for track_d
            track_pts++;
            
            wpt = (waypoint *)elem;
-           if (wpt->creation_time == 0)
-               fatal(MYNAME "-init: Found track point without time!\n");
+           is_fatal((need_time != 0) && (wpt->creation_time == 0),
+               MYNAME "-init: Found track point without time!");
 
            i++;
            if (i == 1) 
@@ -261,7 +264,7 @@ trackfilter_fill_track_list_cb(const route_head *track)     /* callback for track_d
            if (i == track->rte_waypt_ct)
                track_list[track_ct].last_time = wpt->creation_time;
                
-           if ((prev != NULL) && (prev->creation_time > wpt->creation_time))
+           if ((need_time != 0) && (prev != NULL) && (prev->creation_time > wpt->creation_time))
            {
                if (opt_merge == NULL)
                    fatal(MYNAME "-init: Track points badly ordered (timestamp)!\n");
@@ -847,6 +850,21 @@ trackfilter_init(const char *args)
 
        int count = track_count();
 
+/*
+ * check time presence only if required. Options that NOT require time:
+ *
+ * - opt_title (!!! only if no format specifier is present !!!)
+ * - opt_course
+ * - opt_name
+ */
+       need_time = ( 
+           opt_merge || opt_pack || opt_split || opt_sdistance ||
+           opt_move || opt_start || opt_stop || opt_fix || opt_speed ||
+           (trackfilter_opt_count() == 0)      /* do pack by default */
+       );
+       /* in case of a formated title we also need valid timestamps */
+       if ((opt_title != NULL) && (strchr(opt_title, '%') != NULL)) need_time = 1;
+       
        track_ct = 0;
        track_pts = 0;
        
@@ -857,7 +875,8 @@ trackfilter_init(const char *args)
            /* check all tracks for time and order (except merging) */
        
            track_disp_all(trackfilter_fill_track_list_cb, NULL, NULL);
-           qsort(track_list, track_ct, sizeof(*track_list), trackfilter_init_qsort_cb);
+           if (need_time)
+               qsort(track_list, track_ct, sizeof(*track_list), trackfilter_init_qsort_cb);
        }
 }